package com.ssy.lingxi.search.repository;

import com.ssy.lingxi.search.entity.BrowseRecord;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 浏览记录持久化层
 * @author jw.chen
 * @version 2.0.0
 * @date 2021/9/17
 */
public interface BrowseRecordRepository extends JpaRepository<BrowseRecord,Long>, JpaSpecificationExecutor<BrowseRecord> {
    Page<BrowseRecord> findByMemberIdAndMemberRoleIdAndUserIdAndShopId(Long memberId, Long memberRoleId, Long userId, Long shopId, Pageable page);

    BrowseRecord findFirstByMemberIdAndMemberRoleIdAndUserIdAndShopIdAndCommodityIdOrderByCreateTimeDesc(Long memberId, Long memberRoleId, Long userId, Long shopId, Long commodityId);

    @Transactional
    int deleteByMemberIdAndMemberRoleIdAndUserIdAndShopIdAndIdIn(Long memberId, Long memberRoleId, Long userId, Long shopId, List<Long> idList);

    @Transactional
    int deleteByMemberIdAndMemberRoleIdAndUserIdAndShopId(Long memberId, Long memberRoleId, Long userId, Long shopId);

}
